package service

import (
	"myserver/dao"
	"myserver/model"
	"myserver/param"
	"myserver/tool"
)

type WorkService struct {
}

func (s *WorkService) GetWork(work model.Work) model.Work {
	var workDao = dao.WorkDao{MyOrm: tool.MyDb}
	res := workDao.GetSubsidy(&work)
	if res.RowsAffected != 0 {
		return work
	} else {
		return model.Work{}
	}
}
func (s *WorkService) GetRsWork(work model.Work) int64 {
	var workDao = dao.WorkDao{MyOrm: tool.MyDb}
	res := workDao.GetRsWork(&work)
	return res
}
func (s *WorkService) CreateWork(work model.Work) int64 {
	var workDao = dao.WorkDao{MyOrm: tool.MyDb}
	res := workDao.CreateWork(work)
	return res
}

func (s *WorkService) DeleteWork(work model.Work) int64 {
	var workDao = dao.WorkDao{MyOrm: tool.MyDb}
	res := workDao.DeleteWork(work)
	return res
}

func (s *WorkService) UpdateWork(work model.Work) int64 {
	var workDao = dao.WorkDao{MyOrm: tool.MyDb}
	res := workDao.UpdateWork(work)
	return res
}

func (s *WorkService) GetWorkPage(param param.PageParam) param.ResponsePageParam {
	var workDao = dao.WorkDao{MyOrm: tool.MyDb}
	res := workDao.GetWorkPage(tool.ToPageParam(param))
	return res
}

func (s *WorkService) CreateRsWork(reservation model.Reservation) int64 {
	var workDao = dao.WorkDao{MyOrm: tool.MyDb}
	res := workDao.CreateRsWork(reservation)
	if res != 0 {
		return res
	}
	return 0
}

func (s *WorkService) UserWorks(pageParam param.PageParam) param.ResponsePageParam {
	var workDao = dao.WorkDao{MyOrm: tool.MyDb}
	res := workDao.UserWorks(tool.ToPageParam(pageParam))
	return res
}
